package com.example.controller;

import com.example.common.Result;
import com.example.entity.TransferStation;
import com.example.service.TransferStationService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import java.util.List;

/**
 * 文件中转站前端操作接口
 **/
@RestController
@RequestMapping("/transferStation")
public class TransferStationController {

    @Resource
    private TransferStationService transferStationService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody TransferStation transferStation) {
        transferStationService.add(transferStation);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        transferStationService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        transferStationService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody TransferStation transferStation) {
        transferStationService.updateById(transferStation);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        TransferStation transferStation = transferStationService.selectById(id);
        return Result.success(transferStation);
    }

    @GetMapping("/selectAndUserId/{id}")
    public Result selectAndUserId(@PathVariable Integer id) {
        TransferStation transferStation = transferStationService.selectAndUserId(id);
        return Result.success(transferStation);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(TransferStation transferStation) {
        List<TransferStation> list = transferStationService.selectAll(transferStation);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(TransferStation transferStation,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<TransferStation> page = transferStationService.selectPage(transferStation, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/clearTransferStation")
    public Result clearTransferStation(TransferStation transferStation) {
        transferStationService.clearTransferStation(transferStation);
        return Result.success();
    }

}